<?php

	class ProductImage extends AppModel {
		var $name = 'ProductImage';
		var $useTable = 'products_images';
		
		var $belongsTo = array(
			'Product'
		);
		
		var $validate = array();
		
		var $virtualFields = array();
		
		function __construct($id = false, $table = null, $ds = null) {
			parent::__construct($id, $table, $ds);
			$this->virtualFields['pico']		= 'CONCAT(\''. Configure::read('Site.Url.image') . '\', ProductImage.path_url ,\'/\', REPLACE(ProductImage.filename,\'.\',\'_pico.\'))';
			$this->virtualFields['icon']		= 'CONCAT(\''. Configure::read('Site.Url.image') . '\', ProductImage.path_url ,\'/\', REPLACE(ProductImage.filename,\'.\',\'_icon.\'))';
			$this->virtualFields['tiny']		= 'CONCAT(\''. Configure::read('Site.Url.image') . '\', ProductImage.path_url ,\'/\', REPLACE(ProductImage.filename,\'.\',\'_tiny.\'))';
			$this->virtualFields['small']		= 'CONCAT(\''. Configure::read('Site.Url.image') . '\', ProductImage.path_url ,\'/\', REPLACE(ProductImage.filename,\'.\',\'_small.\'))';
			$this->virtualFields['compact']		= 'CONCAT(\''. Configure::read('Site.Url.image') . '\', ProductImage.path_url ,\'/\', REPLACE(ProductImage.filename,\'.\',\'_compact.\'))';
			$this->virtualFields['medium']		= 'CONCAT(\''. Configure::read('Site.Url.image') . '\', ProductImage.path_url ,\'/\', REPLACE(ProductImage.filename,\'.\',\'_medium.\'))';
			$this->virtualFields['large']		= 'CONCAT(\''. Configure::read('Site.Url.image') . '\', ProductImage.path_url ,\'/\', REPLACE(ProductImage.filename,\'.\',\'_large.\'))';
			$this->virtualFields['grande']		= 'CONCAT(\''. Configure::read('Site.Url.image') . '\', ProductImage.path_url ,\'/\', REPLACE(ProductImage.filename,\'.\',\'_grande.\'))';
			$this->virtualFields['original']	= 'CONCAT(\''. Configure::read('Site.Url.image') . '\', ProductImage.path_url ,\'/\', ProductImage.filename)';
		}
		
		function thumbnails($product_id = 0) {
			return $this->find(
				'all',
				array(
					'conditions' => array(
						'ProductImage.product_id' => $product_id
					),
					'recursive' => -1
				)
			);
		}
	}